package com.ruihai.tutorial.faceplusplus;

import com.ruihai.tutorial.faceplusplus.common.CommonConstants;
import com.ruihai.tutorial.faceplusplus.common.FacePPHttpExecutor;
import com.ruihai.tutorial.faceplusplus.common.FacePPUtils;

import javax.net.ssl.SSLException;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;

/**
 * Official demo for Face++ API.
 * Created by Tim on 2017/11/7.
 */
public class Demo {
    public static void main(String[] args) throws Exception{

        File file = new File("D:\\Work\\git\\MLTutorial\\face++\\resource\\pic\\1.jpg");
        byte[] buff = FacePPUtils.getBytesFromFile(file);
        String url = "https://api-cn.faceplusplus.com/facepp/v3/detect";
        HashMap<String, String> map = new HashMap<String, String>();
        HashMap<String, byte[]> byteMap = new HashMap<String, byte[]>();
        map.put(CommonConstants.FACE_PP_API_KEY_NAME, CommonConstants.FACE_PP_API_KEY);
        map.put(CommonConstants.FACE_PP_API_SECRET_NAME, CommonConstants.FACE_PP_API_SECRET);
        byteMap.put("image_file", buff);
        try{
            byte[] bacd = FacePPHttpExecutor.post(url, map, byteMap);
            String str = new String(bacd);
            System.out.println(str);
        }catch (Exception e) {
            e.printStackTrace();
        }
    }


}
